package com.xiaobange.controller.system;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.xiaobange.vo.ResultResponse;
import com.xiaobange.entity.User;
import com.xiaobange.service.impl.UserLoginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @version 1.0
 * @Author 小班哥
 * @Date 2025/4/25 11:28
 * @Explain 系统用户控制器
 */
@RestController
@RequestMapping("/sys")
public class SystemLoginController {

    @Autowired
    private UserLoginServiceImpl userService;

    /**
     * 注册系统用户接口
     * @param user 用户信息
     * @return 结果
     */
    @SaCheckRole(value = "admin")
    @RequestMapping(path = "/register" , method = RequestMethod.PUT)
    public ResultResponse<Map<String,String>> register(@RequestBody User user){
        return userService.register(user);
    }


    /**
     * 系统用户登录
     * @param loginName 账号
     * @param password 密码
     * @return
     */
    @PostMapping("/login")
    public ResultResponse login(@RequestParam String loginName,@RequestParam String password){
        return userService.login(loginName,password);
    }

    /**
     * 退出登录
     */
    @SaCheckLogin
    @GetMapping("/logout")
    public ResultResponse logout(){
        userService.logout();
        return ResultResponse.success(200,"已安全退出");
    }
}
